class Solution(object):
    def minimumTotal(self, triangle):

        n = len(triangle)

    # 创建一个DP表，用于存储从底部到当前点的最小路径和
        dp = [[0] * len(row) for row in triangle]

    # 初始化最后一行的值
        for i in range(len(triangle[-1])):
            dp[-1][i] = triangle[-1][i]

    # 从倒数第二行开始向上计算
        for i in range(n - 2, -1, -1):
            for j in range(len(triangle[i])):
            # 当前点的最小路径和等于当前点的值加上下一行相邻两个点的最小值
                dp[i][j] = triangle[i][j] + min(dp[i + 1][j], dp[i + 1][j + 1])

        return dp[0][0]